package com.ljx.NoteBody.controller;

import com.ljx.NoteBody.common.R;
import com.ljx.NoteBody.dto.CommentsDto;
import com.ljx.NoteBody.entity.Comments;
import com.ljx.NoteBody.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/api/comment")
public class CommentsController {

    @Autowired
    CommentsService commentsService;

    @PostMapping
    private R<String> save(@RequestBody Comments comments){
        commentsService.saveComment(comments);
        return R.success("ok");
    }

    @GetMapping("/{noteId}")
    private R<List<CommentsDto>> comments(@PathVariable("noteId") Long noteId, HttpServletRequest request) {
        return R.success(commentsService.queryCommentByNoteId(noteId, request));
    }
}
